import { reqSearchInfo } from '@/api/index'

// search模块的小仓库
const state = {
    searchInfo: {}
}
const mutations = {
    GETSEARCHINFO(state, val) {
        state.searchInfo = val
    }
}
const actions = {
    async getSearchInfo(context, params) {
        const res = await reqSearchInfo(params)
        if (res.code === 200) {
            context.commit('GETSEARCHINFO', res.data)
        }
    }
}

// getters用于整理数据，功能上类似于计算属性
const getters = {
    goodsList(state) {
        return state.searchInfo.goodsList || [] // 或一个空数组是为了应付恶劣工况，比如没网的话就直接返回undefined了，所以或个空数组 
    },
    trademarkList(state) {
        return state.searchInfo.trademarkList
    },
    attrsList(state) {
        return state.searchInfo.attrsList
    }
}

export default {
    state,
    mutations,
    actions,
    getters
}